/**
 * <pre>
 * ss-fire-collector / LogUtil.java
 * net.apexcns.core.util Class
 * LogUtil
 * <br>
 * 
 * <br>
 * @author ytjeong/apexcns,Inc.
 * @version 1.0
 * @see javadoc
 * @since 2012. 9. 26.
 * </pre>
 */
package net.apexcns.core.util;

import java.io.IOException;

import org.slf4j.Logger;

import system.common.Constants;

import collector.core.CollectConstants;

/** <pre>
 * Class : net.apexcns.core.util.LogUtil / LogUtil.java
 * 	Define Class Object : 
 * <br>
 * </pre>
 * @author ytjeong / apexcns,Inc.
 * @version 1.0
 * @see javadoc
 * @since 2012. 9. 26.
 */

public class LogUtil {

    
	public static void logErrorDisp(Logger pLog, String pLogPrefixStr, String pLogtitle, String pLogMsg) {

	    logDisp(pLog, pLogPrefixStr, pLogtitle, pLogMsg, CollectConstants.LOG_ERROR );
	    return;
	}
	
	public static void logWarnDisp(Logger pLog, String pLogPrefixStr, String pLogtitle, String pLogMsg) {

	    logDisp(pLog, pLogPrefixStr, pLogtitle, pLogMsg, CollectConstants.LOG_WARN );
	    return;
	}
	
	public static void logInfoDisp(Logger pLog, String pLogPrefixStr, String pLogtitle, String pLogMsg) {

	    logDisp(pLog, pLogPrefixStr, pLogtitle, pLogMsg, CollectConstants.LOG_INFO );
	    return;
	}
	
	public static void logDebugDisp(Logger pLog, String pLogPrefixStr, String pLogtitle, String pLogMsg) {

	    logDisp(pLog, pLogPrefixStr, pLogtitle, pLogMsg, CollectConstants.LOG_DEBUG );
	    return;
	}
	
	public static void logDisp(Logger pLog, String pLogPrefixStr, String pLogtitle, String pLogMsg, int pLogLevel ) {

	    switch (pLogLevel) { 
	    case CollectConstants.LOG_ERROR : // error 
		pLog.error(pLogPrefixStr + "----["+pLogtitle+"]-------------------------------------------------");
	    	pLog.error(pLogPrefixStr + pLogMsg);
	    	pLog.error(pLogPrefixStr + "------------------------------------------------------------------------------------");
		break;
	    case CollectConstants.LOG_WARN : // warn 
		pLog.warn(pLogPrefixStr + "----["+pLogtitle+"]-------------------------------------------------");
	    	pLog.warn(pLogPrefixStr + pLogMsg);
	    	pLog.warn(pLogPrefixStr + "------------------------------------------------------------------------------------");
		break;
	    case CollectConstants.LOG_INFO : // info 
		pLog.info(pLogPrefixStr + "----["+pLogtitle+"]-------------------------------------------------");
	    	pLog.info(pLogPrefixStr + pLogMsg);
	    	pLog.info(pLogPrefixStr + "------------------------------------------------------------------------------------");
		break;
	    case CollectConstants.LOG_DEBUG : // debug 
		pLog.debug(pLogPrefixStr + "----["+pLogtitle+"]-------------------------------------------------");
	    	pLog.debug(pLogPrefixStr + pLogMsg);
	    	pLog.debug(pLogPrefixStr + "------------------------------------------------------------------------------------");
		break;
	    }
	    return;
	}
	
	public static String getLogContents(String logName) {

	    String LogPath = System.getProperty("user.dir") + Constants.moduleLogPath;
	    String filename = LogPath + "/" + logName;
	    
	    return getLogFileContents(filename);
	    
	}
	
	public static String getLogFileContents() {

	    String LogPath = System.getProperty("user.dir") + Constants.moduleLogPath;
	    String LogName = "state.log";
	    String filename = LogPath + "/" + LogName;
	    
	    return getLogFileContents(filename);
	    
	}
	
	public static String getLogFileContents(String logPathName) {

	    String msg = "";
	    String encoding = "utf-8";
	    String filename = logPathName;
	    try {
	    	msg = FileUtil.readTextFile(filename, encoding);
	    } catch (IOException e) {
	    	e.printStackTrace();
	    }
	    
	    String hMsg = StringUtil.escapeHtmlBr(StringUtil.escapeHtml(msg));
//	    System.out.println(":: Contents L Out :: ========================= ");
//	    System.out.println(":: Message ::" + msg);
//	    System.out.println(":: Contents H Out :: ========================= ");
//	    System.out.println(":: html Message ::" + hMsg);
	    
	    return hMsg;
	    
	}

	public static void main(String[] args) {
	    	getLogFileContents();
	}
	
}
